package com.Day11.TreeSet;

import java.util.TreeSet;

/**
 * @author: 若若叶
 * @date: 2021/7/19 12:56
 * FileName: Test
 * Description:
 */
public class Test {
    public static void main(String[] args) {
        TreeSet<User> treeSet = new TreeSet<User>();
        //添加对象
        treeSet.add(new User("张三",20));
        treeSet.add(new User("安安",20));
        treeSet.add(new User("李四",23));
        treeSet.add(new User("王五",19));

        //按照年龄从小到大，年龄一样，按名字从小到大
        for (User u:treeSet) {
            System.out.println(u);
        }

        /*
        User{username='王五', age=19}
        User{username='安安', age=20}
        User{username='张三', age=20}
        User{username='李四', age=23}
         */
    }
}
